home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / wxlslib.zip / xlslib / examples / regdemo.lsp < prev    next >
Text File  |  1992-02-20  |  1KB  |  39 lines

  1.  
  2. ;; set up some simulated data
  3. (def x (append (iseq 1 18) (list 30 40)))
  4. (def y (+ x (* 2 (normal-rand 20))))
  5.  
  6. ;; construct the plot
  7. (def myplot (plot-points x y))
  8.  
  9. ;; add a new "mouse mode", with menu title, cusror and mouse method name
  10. (send myplot :add-mouse-mode 'point-moving
  11.       :title "Point Moving"
  12.       :cursor 'finger
  13.       :click :do-point-moving)
  14.  
  15. ;; add the new mouse method
  16. (defmeth myplot :do-point-moving (x y a b)
  17.   (let ((p (send self :drag-point x y :draw nil)))
  18.     (if p (send self :set-regression-line))))
  19.  
  20. ;; add method for drawing the regression line for the current data
  21. (defmeth myplot :set-regression-line ()
  22.   (let ((coefs (send self :calculate-coefficients)))
  23.     (send self :clear-lines :draw nil)
  24.     (send self :abline (select coefs 0) (select coefs 1))))
  25.  
  26. ;; add method for calculating regression coefficients for current data
  27. (defmeth myplot :calculate-coefficients ()
  28.   (let* ((i (iseq 0 (- (send self :num-points) 1)))
  29.          (x (send self :point-coordinate 0 i))
  30.          (y (send self :point-coordinate 1 i))
  31.          (m (regression-model x y :print nil)))
  32.     (send m :coef-estimates)))
  33.  
  34. ;; add the regression line
  35. (send myplot :set-regression-line)
  36.  
  37. ;; put the plot in "point moving" mode
  38. (send myplot :mouse-mode 'point-moving)
  39.